package com.xianyun.site.support.executor.handle.sms.v20201114.impl;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.xianyun.site.support.domain.model.SmsMessage;
import com.xianyun.site.support.dto.SmsReceiveCmd;
import com.xianyun.site.support.executor.handle.sms.BaseSmsStrategy;
import com.xianyun.site.support.gatewayimpl.database.SmsConfigMapper;
import com.xianyun.site.support.gatewayimpl.database.domainobject.SmsConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * 短信请求策略
 * @author mac_zyj
 */
@Component
public class IBaseSmsResultStrategyImpl extends BaseSmsStrategy {

    @Autowired
    private SmsConfigMapper configMapper;


    @Override
    public SendSmsRequest initSendSmsRequest(SmsMessage message) {
        // 组装请求对象-具体描述见控制台-文档部分内容
        SendSmsRequest request = new SendSmsRequest();
        SmsConfig smsConfig=configMapper.selectSmsConfigByConfigName(message.getConditionName());
        Assert.notNull(smsConfig,"请检查系统配置!");
        // 必填:待发送手机号
        request.setPhoneNumbers(message.getPhoneNumber());
        // 必填:短信签名-可在短信控制台中找到
        request.setSignName(smsConfig.getSignName());
        // 必填:短信模板-可在短信控制台中找到
        request.setTemplateCode(smsConfig.getTemplateCode());
        // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
        request.setTemplateParam("{\"name\":\"" + message.getOperateName() + "\"}");
        return request;
    }
}
